﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ProjectWebNhac.BUS;
using System.Data;

namespace ProjectWebNhac.GUI.Admin
{
    public partial class QL_Comment : System.Web.UI.Page
    {

        BinhLuanAlbumBus blalbum = new BinhLuanAlbumBus();
        BinhLuanBaiHatBus blbaihat = new BinhLuanBaiHatBus();
        BinhLuanVideoBus blvideo = new BinhLuanVideoBus();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
                {
            loadtrang();
                }
        }

        private void loadtrang()
        {
            gvBLBaiHat.DataSource = blbaihat.LayHetListBinhLuan();
            gvBLBaiHat.DataBind();

            gvBLVideo.DataSource = blvideo.LayBinhLuanVideo();
            gvBLVideo.DataBind();

            gvBLAlbum.DataSource = blalbum.LayHetListBinhLuan();
            gvBLAlbum.DataBind();
        }


        protected void lnkBLBaiHat_Click(object sender, EventArgs e)
        {
            divBLAlbum.Visible = false;
            divBLVideo.Visible = false;
            divBLBaiHat.Visible = true;
        }

        protected void lnkBLVideo_Click(object sender, EventArgs e)
        {
            divBLAlbum.Visible = false;
            divBLVideo.Visible = true;
            divBLBaiHat.Visible = false;
        }

        protected void lnkBlAlbum_Click(object sender, EventArgs e)
        {
            divBLAlbum.Visible = true;
            divBLVideo.Visible = false;
            divBLBaiHat.Visible = false;
        }

        protected void gvBLBaiHat_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName.Equals("Xoa"))
            {
                int MaBinhLuan = int.Parse(e.CommandArgument.ToString());
                blbaihat.XoaBinhLuan(MaBinhLuan);
                loadtrang();
            }

            if (e.CommandName.Equals("ChiTiet"))
            {
                int MaBinhLuan = int.Parse(e.CommandArgument.ToString());
                DataTable dt = blbaihat.LayChiTietBinhLuan(MaBinhLuan);
                txtTenBaiHat.Text=dt.Rows[0]["TenBaiHat"].ToString();
                txtThoiGian.Text=dt.Rows[0]["ThoiGian"].ToString();
                txtLoiBinh.Text=dt.Rows[0]["LoiBinh"].ToString();
                txtTaiKhoan.Text = dt.Rows[0]["TaiKhoan"].ToString();
                txtMaBinhLuan.Text = dt.Rows[0]["MaBinhLuan"].ToString();
            }
        }

        protected void gvBLVideo_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName.Equals("Xoa"))
            {
                int MaBinhLuan = int.Parse(e.CommandArgument.ToString());
                blvideo.XoaBinhLuan(MaBinhLuan);
                loadtrang();
            }

            if (e.CommandName.Equals("ChiTiet"))
            {
                int MaBinhLuan = int.Parse(e.CommandArgument.ToString());
                DataTable dt = blvideo.LayChiTietBinhLuan(MaBinhLuan);
                txtTenVideo.Text = dt.Rows[0]["TenVideo"].ToString();
                txtThoiGianVideo.Text = dt.Rows[0]["ThoiGian"].ToString();
                txtLoiBinhVideo.Text = dt.Rows[0]["LoiBinh"].ToString();
                txtTaiKhoanVideo.Text = dt.Rows[0]["TaiKhoan"].ToString();
                txtMaBinhLuanVideo.Text = dt.Rows[0]["MaBinhLuan"].ToString();

            }
        }

        protected void gvBLAlbum_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName.Equals("Xoa"))
            {
                int MaBinhLuan = int.Parse(e.CommandArgument.ToString());
                blalbum.XoaBinhLuan(MaBinhLuan);
                loadtrang();
            }

            if (e.CommandName.Equals("ChiTiet"))
            {
                int MaBinhLuan = int.Parse(e.CommandArgument.ToString());
                DataTable dt = blalbum.LayChiTietBinhLuan(MaBinhLuan);
                txtTenAlbum.Text = dt.Rows[0]["TenAlbum"].ToString();
                txtThoiGianAlbum.Text = dt.Rows[0]["ThoiGian"].ToString();
                txtLoiBinhAlbum.Text = dt.Rows[0]["LoiBinh"].ToString();
                txtTaiKhoanAlbum.Text = dt.Rows[0]["TaiKhoan"].ToString();
                txtMaBinhLuanAlbum.Text = dt.Rows[0]["MaBinhLuan"].ToString();
            }
        }

        protected void lnkXoaBaiHat_Click(object sender, EventArgs e)
        {
            int MaBinhLuan = int.Parse(txtMaBinhLuan.Text);
            blbaihat.XoaBinhLuan(MaBinhLuan);
            loadtrang();
        }

        protected void lnkXoaVideo_Click(object sender, EventArgs e)
        {
            int MaBinhLuan = int.Parse(txtMaBinhLuan.Text);
            blvideo.XoaBinhLuan(MaBinhLuan);
            loadtrang();
        }

        protected void lnkXoaAlbum_Click(object sender, EventArgs e)
        {
            int MaBinhLuan = int.Parse(txtMaBinhLuan.Text);
            blalbum.XoaBinhLuan(MaBinhLuan);
            loadtrang();
        }
    }
}